//
//  HWShirenzhengViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/10.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWShirenzhengViewController.h"

@interface HWShirenzhengViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *beijingseView;
@property (weak, nonatomic) IBOutlet UITextField *xingmingTextField;
@property (weak, nonatomic) IBOutlet UITextField *shengfenTextFeild;
@property (weak, nonatomic) IBOutlet UIButton *tijiaoButon;

@end

@implementation HWShirenzhengViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setupUI];
    
}


// 设置密码

- (void)setupUI {
    
    self.navigationItem.title =  @"实名认证";
    self.view.backgroundColor =beijingyanSe;
    self.xingmingTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
    self.xingmingTextField.leftViewMode = UITextFieldViewModeAlways;
    self.xingmingTextField.layer.cornerRadius =  2;
    self.xingmingTextField.layer.masksToBounds = YES;
    self.xingmingTextField.delegate = self;
    
    self.shengfenTextFeild.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
    self.shengfenTextFeild.leftViewMode = UITextFieldViewModeAlways;
    self.shengfenTextFeild.layer.cornerRadius =  2;
      self.shengfenTextFeild.layer.masksToBounds = YES;
      self.shengfenTextFeild.delegate = self;

    
    
    self.beijingseView.layer.cornerRadius =  8;
    self.beijingseView.layer.masksToBounds = YES;
    
    self.tijiaoButon.layer.cornerRadius =  2;
    self.tijiaoButon.layer.masksToBounds = YES;
      
     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView)];
     [self.view addGestureRecognizer:tap];
     
    

    
}

- (void)tapView {
    
    [self.view endEditing:YES];
    
}



- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    
    return  YES;
    
}




//提交按钮
- (IBAction)tijiaoTapBut:(UIButton *)sender {
    
    
    if (!(self.xingmingTextField.text.length > 0)) {
      
          [MBProgressHUD showError:@"请输入姓名"];
          
          return;
          
          
          
      }else if (!(self.shengfenTextFeild.text.length > 0)) {
          
             [MBProgressHUD showError:@"请输入15 位或 18 位身份证号"];
               
               return;
          
          
          
      }else if (!(self.shengfenTextFeild.text.length > 14 )) {
          
             [MBProgressHUD showError:@"请输入15 位或 18 位身份证号"];
               
               return;
          
          
          
      } else if (!(self.shengfenTextFeild.text.length < 19 )) {
          
             [MBProgressHUD showError:@"请输入15 位或 18 位身份证号"];
               
               return;
          
          
          
      }
    
    
    
       NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
       NSString *uid =  [HWLocallyStoredData getLoginUserID];
       NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
       NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
       NSString *name = self.xingmingTextField.text;
       NSString *idcard =  self.shengfenTextFeild.text;
       
       
               
               
               
                    NSDictionary *parametes = @{      @"ios" : @"1",
                                              @"ct" : @"app",
                                               @"ac" : @"shiming_edit",
                                               @"t" : tStr,
                                               @"uid":uid,
                                                @"name":name,
                                                @"idcard":idcard,
                                               @"sign" :signStrMd5
                                              
                                               };
               
               
                   [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                         
                        

                         NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                         if ([codeStr intValue] == 1) {
                        
                             
                             [self.navigationController popViewControllerAnimated:YES];
                             
                             
    
                        
                             
                       
                       

                              
                         } else {
                             
                           [MBProgressHUD showError:response[@"message"]];
                                           
                       
                             
                         }
                         
                    
                         
                     } failure:^(NSString *error) {
                        // [SVProgressHUD dismiss];
                         
                         [MBProgressHUD showSuccess:@"登录失败"];
                         [MBProgressHUD hideHUD];
                         
                         
                         
                         
                     }];
               
       
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


@end
